import java.util.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class BobTimer implements ActionListener {
	public int timertick=0;
	public int type; // 0 is renderer, 1 is weather, 2 is animals
	public BobTimer(int T)
	{
		super();
		type = T;

		Magic_Eight_Ball.prove_Bob_Timer_Exists();
		//This exists onl for testing

	}

	public void actionPerformed(ActionEvent e) {

		if(timertick>SimulationConstants.speed*5)
		{
			if(type==0)
				SimulationConstants.mainUI.updateImage();
			if(SimulationConstants.pauseButton){   
				timertick=0;
				Tick();
			}
		}
		else
			timertick++;
	}


	/*
	 * The timer class is used to handle periodically calling the renderer, Update the atmosphere, and call the Behavoir manager.
	 * The system clock calls the "Tick()" function at an interval set by the speed variable
	 */
	final double seismicChance = 0.01;

	int Atmosphere_to_Animal_ratio=5;
	public int animaltick=0;

	public void Tick()
	{
		animaltick++; 
		if(animaltick>=Atmosphere_to_Animal_ratio)
		{
			if(type==1)
				WindMap.UpdateWind();
			animaltick=0;
		}

		//Update Animals
		if(type==2)
			AnimalHandlerObject.updateAnimals();

		Random R = new Random();
		if(R.nextDouble()<seismicChance&&type==1)//We have a random seismic event
		{
			loc s = new loc(R.nextInt(SimulationConstants.simsize),R.nextInt(SimulationConstants.simsize));//pick a random location 
			TempMap.SeismicTemp(s);//Make it very hot
			HumidMap.SeismicHumid(s);//make it very humid

		}
	}

}